package com.xiaohong.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.order.dao.OrderMapper;
import com.xiaohong.order.pojo.Order;
import com.xiaohong.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    /**
     * 条件+分页查询Order
     * @param order 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Order> findPage(Order order, int page, int size){
        // 构建查询条件
        QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>(order);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return orderMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Order
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Order> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return orderMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Order
     * @param order
     * @return
     */
    @Override
    public List<Order> findList(Order order){
        // 构建查询条件
        QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>(order);
        // 查询数据
        return orderMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Order
     * @param id
     */
    @Override
    public void delete(String id){
        orderMapper.deleteById(id);
    }

    /**
     * 根据ID修改Order
     * @param order
     */
    @Override
    public void update(Order order){
        orderMapper.updateById(order);
    }

    /**
     * 增加Order
     * @param order
     */
    @Override
    public void add(Order order){
        orderMapper.insert(order);
    }

    /**
     * 根据ID查询Order
     * @param id
     * @return
     */
    @Override
    public Order findById(String id){
        return  orderMapper.selectById(id);
    }

    /**
     * 查询全部Order数据
     * @return
     */
    @Override
    public List<Order> findAll() {
        return orderMapper.selectList(null);
    }
}
